﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Collections;

namespace WindowsFormsApplication3.Administraror.Humanresource
{
    using alldataset.fullldatasetTableAdapters;

    public partial class EmployetransferForm : Form
    {
        public EmployetransferForm()
        {
            InitializeComponent();
            
        }

        /// <summary>
        /// LOAD EMPLOYE DETAILS ONLOAD
        /// </summary>
        public void employecomboload()
        {
            EmployeemasterTableAdapter empadapt = new EmployeemasterTableAdapter();
              empadapt.Connection = new OleDbConnection(Program.ConnStr);
            DataTable dt = empadapt.Getemployeecodeandname();
           
            if (dt.Rows.Count != 0)
            {
                cmbemployee.DisplayMember = "EMPCODE";
                cmbemployee.ValueMember = "PK";
                cmbemployee.DataSource = dt;
                txtempname.Text = dt.Rows[0]["NAME"].ToString();
                txtpassport.Text = dt.Rows[0]["PASSPORTNUM"].ToString();
                txtvisa.Text = dt.Rows[0]["VISANUM"].ToString();
            }

        }

        private void EmployetransferForm_Load(object sender, EventArgs e)
        {
            employecomboload();

        }

  
       

        private void button1_Click(object sender, EventArgs e)
        {
            if (validationcontrol())
            {
                ArrayList arrylst = new ArrayList();
                arrylst.Add(int.Parse(cmbemployee.SelectedValue.ToString()));
                arrylst.Add(txtempname.Text);
                arrylst.Add(txtvisa.Text);
                arrylst.Add(cmbemployee.Text);
                


                EmpLoctnChangeForm empchange = new EmpLoctnChangeForm(arrylst);

                empchange.ShowDialog();
            }

        }



        /// <summary>
        /// Validates every user Input
        /// </summary>
        /// <returns></returns>

        public Boolean validationcontrol()
        {
            Boolean sucess = false;
            if (cmbemployee.Text.Trim() == null || cmbemployee.Text.Trim() == "")
            {
                lblstatus.Text = "Enter EmpCode";
                cmbemployee.Focus();
                cmbemployee.Text = "";
            }
            else if (txtvisa.Text.Trim() == null || txtvisa.Text.Trim() == "")
            {
                lblstatus.Text = "Enter Visa Num";
                txtvisa.Focus();
                txtvisa.Text = "";
            }
            else if (txtempname.Text.Trim() == null || txtempname.Text.Trim() == "")
            {

                txtempname.Focus();
                lblstatus.Text = "Enter an Empname";
                txtempname.Text = "";
            }

            else if (txtpassport.Text.Trim() == null || txtpassport.Text.Trim() == "")
            {

                txtpassport.Focus();
                lblstatus.Text = "Enter an valid Passportno";
                txtpassport.Text = "";
            }
           
            else
            {

                sucess = true;
            }
            return sucess;
        }
        /// <summary>
        /// LOAD EMPLOYE DETAILS asper selected employee
        /// occurs when comboboxselectionchange
        /// </summary>
        public void employecombochangeevent()
        {
            EmployeemasterTableAdapter empadapt = new EmployeemasterTableAdapter();
            empadapt.Connection = new OleDbConnection(Program.ConnStr);
            DataTable dt = empadapt.GetDataByemploye(int.Parse(cmbemployee.SelectedValue.ToString()));

            if (dt.Rows.Count != 0)
            {
                //cmbemployee.DisplayMember = "EMPCODE";
               // cmbemployee.ValueMember = "PK";
              //  cmbemployee.DataSource = dt;
                txtempname.Text = dt.Rows[0]["NAME"].ToString();
                txtpassport.Text = dt.Rows[0]["PASSPORTNUM"].ToString();
                txtvisa.Text = dt.Rows[0]["VISANUM"].ToString();
            }

        }

        private void cmbemployee_SelectedIndexChanged(object sender, EventArgs e)
        {
            employecombochangeevent();
            datagridfill();
        }
        public void datagridfill()
        {
            EmployeelocationmastertableTableAdapter empadapt = new EmployeelocationmastertableTableAdapter();
            empadapt.Connection =new OleDbConnection( Program.ConnStr);
            DataTable dt = empadapt.GetDatabyemppk(int.Parse(cmbemployee.SelectedValue.ToString()));
          //  if (dt.Rows.Count != 0)
           // {
                dtemplocation.DataSource = dt;
          //  }

        }
        

    }
}
